//
//  FRQContactUsViewController.m
//  FRQBluetoothKit_Example
//
//  Created by admin on 2023/10/25.
//  Copyright © 2023 xuchunhai. All rights reserved.
//

#import "FRQContactUsViewController.h"
#import "ContactUsViews.h"
@interface FRQContactUsViewController ()
@property (nonatomic,strong) ContactUsViews *ContactUsView;
@end

@implementation FRQContactUsViewController
- (ContactUsViews *)ContactUsView{
    if (nil==_ContactUsView) {
        _ContactUsView=skXibView(@"ContactUsViews");
        [self.view addSubview:_ContactUsView];
        [_ContactUsView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_topLayoutGuide);
            make.bottom.mas_equalTo(self.mas_bottomLayoutGuide);
            make.right.left.mas_equalTo(0);
        }];
        @weakify(self)
        [[_ContactUsView.btnSend rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            [self appUserNeedSupport];
        }];
        [[_ContactUsView.btnBack rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)

            [self.navigationController popViewControllerAnimated:YES];
            [self dismissViewControllerAnimated:YES completion:^{
                if(self.bvalCount == 1){
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"ContactUs" object:nil];
                }
            }];
        }];
    }
    return _ContactUsView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.ContactUsView.hidden=NO;
    self.title=@"Contact Us";
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}
/*
 app/user/need/support
 用户寻求支持
 */
-(void)appUserNeedSupport{
    _ContactUsView.btnSend.enabled = NO;
    NSString *title=[NSString stringWithFormat:@"%@",self.ContactUsView.txtTitle.text];
    
    NSString *message=[NSString stringWithFormat:@"%@",self.ContactUsView.txtMessage.text];
    
    NSDictionary *dic=@{@"subject":title,
                        @"message":message
    };
    [skNetTools skPOSTWithURL:[NSString stringWithFormat:@"%@%@",skURL,@"app/user/need/support"] parameters:dic cachePolicy:0 callback:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        NSLog(@"数据=%@",responseObject);
        skNetModel *model=responseObject;
        if(model.code == 200){
            self.ContactUsView.txtTitle.text = @"";
            self.ContactUsView.txtMessage.text = @"";
        }
        _ContactUsView.btnSend.enabled = YES;
        [SkToast SkToastShow:model.msg];
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
